package com.tuanzi.loan.web.bean.galaxycard;

import com.tuanzi.loan.business.entity.common.CommProductChannel;
import com.tuanzi.loan.business.entity.common.CommProductId;
import com.tuanzi.loan.business.service.common.CommProductChannelService;
import com.tuanzi.loan.business.service.common.CommProductIdService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.web.configuration.JSFListingBean;

import com.tuanzi.loan.vo.request.galaxycard.GalaxyCardUserInfoSearchRequest;
import com.tuanzi.loan.vo.response.galaxycard.GalaxyCardUserInfoSearchResponse;
import com.tuanzi.loan.web.lazy.galaxycard.GalaxyCardUserInfoDataModel;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.util.List;

/**
 * 银河黑卡用户信息
 * @author JinRuiyang 2018/1/8 18:42:09
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class GalaxyCardUserListBean extends JSFListingBean<GalaxyCardUserInfoSearchRequest, GalaxyCardUserInfoSearchResponse> {

    private List<CommProductId> commProductIds;
    private List<CommProductChannel> commProductChannels;

    private CommProductIdService commProductIdService;
    private CommProductChannelService commProductChannelService;

    @Autowired
    public GalaxyCardUserListBean(CommProductIdService commProductIdService, CommProductChannelService commProductChannelService) {
        this.commProductIdService = commProductIdService;
        this.commProductChannelService = commProductChannelService;
    }

    @PostConstruct
    private void init() {
        initLazyDataModel();
        commProductIds = commProductIdService.findAll();
        commProductChannels = commProductChannelService.findAll();
    }

    public void onReset() {
        initLazyDataModel();
    }

    public void onRefresh(){
        lazyDataModel = new GalaxyCardUserInfoDataModel($);
        addSuccessfullyMessage();
    }

    private void initLazyDataModel() {
        $ = new GalaxyCardUserInfoSearchRequest();
        $.setStatus(1);
        lazyDataModel = new GalaxyCardUserInfoDataModel($);
    }
}